package com.gin.kotlin.vegetables_kot.base

import android.view.View

class ViewUtils {
    companion object{
        /**
         * 根据数据是否存在返回 [View.VISIBLE] 或 [View.GONE]
         * @param data Any?
         * @param reversed Boolean
         */
        fun visible(data: Any?, reversed: Boolean = false): Int {
            if (data is Collection<*>?) {
                return if (data.isNullOrEmpty() == reversed) View.VISIBLE else View.GONE
            }
            if (data is String?) {
                return if (data.isNullOrEmpty() == reversed) View.VISIBLE else View.GONE
            }
            return if (data.toString().isEmpty() == reversed) View.VISIBLE else View.GONE
        }

        /**
         * 根据布尔值返回 [View.VISIBLE] 或 [View.GONE]
         * @param visible Boolean
         * @return Int
         */
        fun visible(visible:Boolean) = if (visible) View.VISIBLE else View.GONE
    }
}